
package com.zhu.salesmanagement;

import java.net.URI;

import org.xmlrpc.android.XMLRPCClient;

import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.MKEvent;
import com.baidu.mapapi.MKGeneralListener;
import android.app.Application;
import android.util.Log;

/**
 * Application 地图,URL 初始化  
 * 
 */

public class SalesApplication extends Application {

    static public SalesApplication mApplicaton;
    static public String mStrKey = "3758B7D2F6251E6D997682DD70C6D9BD9B2DA4C0"; //Map key
    boolean m_bKeyRight = true;
    private XMLRPCClient mXMLRPCClient = null; //XMLRPC Client
    private URI uri = URI
            .create("http://mobile.sfworldwide.com:8000/dmsmobile15.rem"/*"http://mobile.sfworldwide.com:8000/dmsmobile.rem"/*"http://www.infoyoung.com:801/dms/dmsmobile.rem"/*"http://172.31.1.49:8000/dmsmobile.rem"/* "http://114.80.243.90:8000/dmsmobile.rem" */);
    private URI testuri = URI.create("http://www.infoyoung.com:801/dms/dmsmobile14.rem");
    private boolean isTest = false;

    private BMapManager mBMapManager = null; //地图管理

    public static class MyGeneralListener implements MKGeneralListener {
        @Override
        public void onGetNetworkState(int iError) {
            Log.d("MyGeneralListener", "onGetNetworkState error is " + iError);
        }

        @Override
        public void onGetPermissionState(int iError) {
            if (iError == MKEvent.ERROR_PERMISSION_DENIED) {
            }
        }
    }

    @Override
    public void onCreate() {
        mApplicaton = this;
        mXMLRPCClient = new XMLRPCClient(uri);
        mBMapManager = new BMapManager(this);
        mBMapManager.init(SalesApplication.mStrKey, new SalesApplication.MyGeneralListener());
        super.onCreate();
    }

    public XMLRPCClient getXMLRPCClient() {
        return mXMLRPCClient;
    }

    /**
     * 自定义IP登录
     */
    public void setXMLRPCClient(String ip) {
        mXMLRPCClient = null;
        mXMLRPCClient = new XMLRPCClient("http://" + ip + "/dmsmobile15.rem");
    }

    public void changeXMLRPCClient() {
        isTest = !isTest;
        if(isTest){
            mXMLRPCClient = null;
            mXMLRPCClient = new XMLRPCClient(testuri);
        }else{
            mXMLRPCClient = null;
            mXMLRPCClient = new XMLRPCClient(uri);
        }
    }

    public BMapManager getMapManager(){
        return mBMapManager;
    }

    @Override
    public void onTerminate() {
        if (mBMapManager != null) {
            mBMapManager.destroy();
            mBMapManager = null;
        }
        super.onTerminate();
    }
}
